<template>
    <div class="">
        <el-dialog title="编辑重点家庭" :visible.sync="dialog" width="40%" :before-close="dialogClose">
            <el-form ref="formData" :model="formData" label-width="100px">
				<el-form-item label="所属户档" prop="homeid">
				    <el-select v-model="formData.homeid" style="width: 100%;" placeholder="请选择所属户档">
				    	<el-option :label="item.header + '(' + item.sn + ')'" :value="parseInt(item.id)" v-for="(item, index) in Home"></el-option>
				    </el-select>
				</el-form-item>
				
				<el-row>
					<el-col :span="12">
						<el-form-item label="类别" prop="cate">
							<el-select v-model="formData.cate" style="width: 100%;" placeholder="请选择所属类别">
								<el-option :label="item" :value="item" v-for="(item, index) in Site.familyCate"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="A28" prop="a28">
						    <el-input v-model="formData.a28" placeholder="请输入A28金额">
								<template slot="append">元</template>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
				
				
				<el-row>
					<el-col :span="12">
						<el-form-item label="A29" prop="a29">
						    <el-input v-model="formData.a29" placeholder="请输入A29金额">
								<template slot="append">元</template>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="A30" prop="a30">
						    <el-input v-model="formData.a30" placeholder="请输入A30金额">
								<template slot="append">元</template>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
				
				<el-row>
					<el-col :span="12">
						<el-form-item label="A31" prop="a31">
						    <el-input v-model="formData.a31" placeholder="请输入A31金额">
								<template slot="append">元</template>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="A32" prop="a32">
						    <el-input v-model="formData.a32" placeholder="请输入A32金额">
								<template slot="append">元</template>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>

            	<el-form-item>
            		<el-button @click="dialogClose">取 消</el-button>
            		<el-button type="primary" @click="formSubmit">确 定</el-button>
            	</el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
export default {
	components: {
	},
	data() {
		return {
			dialog: false,
			Site: [],
			Home: [],
			Hamlet: [],
			formData: {
				id: 0,
				homeid: '', //所属户档
				cate: '', //类别
				a28: '', 
				a29: '', 
				a30: '', 
				a31: '', 
				a32: '', 
			},
			homeid:0
		}
	},
	created() {
	},
	watch: {
		dialog () {
			if(!this.dialog) {
				this.clearFormData()
				this.$emit('getData')
			} else {
				this.getHome()
				this.getSite()
			}
		}
	},
	methods: {
		getHome () {
			this.$apiPost('House/getHome').then(res => {
				if(res.code == 1) {
					this.Home = res.data
				}
			})
		},
		getSite () {
			this.$apiPost('Index/getSiteFile').then(res => {
				if(res.code == 1) {
					this.Site = res.data
				}
			})
		},
		dialogClose(){
			this.$emit('dialogToggle')
		},
		clearFormData () {
			for(let i in this.formData){
				if(i == 'id') {
					this.formData[i] = 0
				} else {
					this.formData[i] = ''
				}
			}
		},
		// 保存编辑
		formSubmit() {
			if(!this.formData.homeid){
				return this.$message.error('请选择所属户档！')
			}
			this.$apiPost('Family/editData', this.formData).then(res => {
				if(res.code == 1) {
					this.$message(res.msg)
					this.dialogClose()
				} else {
					this.$message(res.msg)
				}
			})
		},
	}
}
</script>
<style scoped>
	.mselect{
		width: 100%;
	}
	.mtdiv{
		margin-top: 10px;
		display: inline-block;
		width: 100%;
	}
	.mtdiv .mtdiv-v{
		float: left;
		width: 50%;
		margin-bottom: 5px;
		display: flex;
		align-items: center;
	}
	.mtdiv .mtdiv-v label{
		float: left;
		margin-right: 10px;
	}
	.mtdiv .el-input{
		float: left;
		width: 80%;
		margin: 5px 0;
	}
	.el-cascader {
		line-height: 32px !important;
	}
	.el-input__inner {
	    height: 32px !important;
	    line-height: 32px !important;
	}
	.el-input__icon {
		line-height: 32px !important;
	}
</style>
